import openpyxl
import csv


def excel_to_csv_with_format(excel_path, csv_path, sheet_name=None):

    wb = openpyxl.load_workbook(excel_path, data_only=True)
    sheet = wb[sheet_name] if sheet_name else wb.active
    with open(csv_path, 'w', newline='', encoding='utf-8') as f:
        writer = csv.writer(f)

        for row in sheet.iter_rows(values_only=True):
            formatted_row = []
            for value in row:

                formatted_row.append(value)
            writer.writerow(formatted_row)

    print(f"Excel 转换为 CSV 完成，文件保存为: {csv_path}")
if __name__ == '__main__':
    excel_to_csv_with_format("TB_ZY_FYMXB_202501.xlsx","TB_ZY_FYMXB_202501.csv",None)